package com.swagger.demo.admin.custom.controller;

import com.jfinal.core.Controller;
import com.jfinal.core.Path;
import com.jfinal.kit.Kv;
import com.jfinal.kit.Ret;
import com.lastb7.swagger.annotation.ApiResCustom;
import com.swagger.demo.admin.bean.CordonAlarmData;
import com.swagger.demo.admin.bean.CordonAlarmResult;
import com.swagger.demo.admin.custom.bean.DemoExtendResult;
import com.swagger.demo.admin.custom.bean.DemoInnerResult;
import com.swagger.demo.admin.custom.bean.DemoResult;
import com.swagger.demo.admin.custom.bean.GwcGridData;
import com.swagger.demo.admin.custom.bean.GwcGridData2;
import com.swagger.demo.admin.custom.bean.GwcGridData3;
import com.swagger.demo.admin.custom.bean.RetDoc;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * @author: lbq
 * 联系方式: 526509994@qq.com
 * 创建日期: 2020/9/16
 */
@Path("/customRes")
@Api(description = "HelloWorld", tags = "自定义返回值")
public class CustomController extends Controller {


    @ApiOperation(value = "2.9.1新增实验性质的自定义返回值格式", notes = "对接强势第三方,需要按对方约定格式返回数据", position = 1)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "paramA", value = "参数a", defaultValue = "1111"),
            @ApiImplicitParam(name = "paramB", value = "参数b", defaultValue = "222"),
    })
    @ApiResCustom(CordonAlarmResult.class)
    public void test1(String paramA, String paramB) {
        CordonAlarmData cordonAlarmData = new CordonAlarmData();
        cordonAlarmData.setAction(1);
        cordonAlarmData.setDevId(1);
        cordonAlarmData.setEid(5);
        cordonAlarmData.seteType(24);
        cordonAlarmData.setUpTime(System.currentTimeMillis() / 1000);

        CordonAlarmResult cordonAlarmResult = new CordonAlarmResult();
        cordonAlarmResult.setCode(0);
        cordonAlarmResult.setSysTime(System.currentTimeMillis() / 1000);
        cordonAlarmResult.setData(cordonAlarmData);

        this.renderJson(cordonAlarmResult);
    }

    @ApiOperation(value = "2.10.1第三方返回值[无描述注解]", notes = "第三方提供的类,无注解,2.9.1之前的版本会报错. 2.10.1之后忽略掉", position = 2)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "paramA", value = "参数a", defaultValue = "1111"),
            @ApiImplicitParam(name = "paramB", value = "参数b", defaultValue = "222"),
    })
    @ApiResCustom(Ret.class)
    public void test2(String paramA, String paramB) {
        this.renderJson(Ret.ok("保存成功"));
    }

    @ApiOperation(value = "2.10.1第三方返回值[添加描述]", notes = "对于第三方类,添加一个描述类用于生成对应的文档,不影响第三方类", position = 3)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "paramA", value = "参数a", defaultValue = "1111"),
            @ApiImplicitParam(name = "paramB", value = "参数b", defaultValue = "222"),
    })
    @ApiResCustom(RetDoc.class)
    public void test3(String paramA, String paramB) {
        this.renderJson(Ret.fail("保存失败"));
    }

    @ApiOperation(value = "2.10.1第三方返回值[继承父类描述1]", notes = "关注data字段的描述", position = 4)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "paramA", value = "参数a", defaultValue = "1111"),
            @ApiImplicitParam(name = "paramB", value = "参数b", defaultValue = "222"),
    })
    @ApiResCustom(DemoResult.class)
    public void test4(String paramA, String paramB) {
        DemoResult demo = new DemoResult();
        demo.setCode(0);
        demo.setMsg("成功");
        demo.setData(Kv.by("paramA", paramA).set("paramB", paramB));

        this.renderJson(demo);
    }

    @ApiOperation(value = "2.10.1第三方返回值[覆盖父类描述2]", notes = "相同的字段,子类的描述优先级比父类高", position = 5)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "paramA", value = "参数a", defaultValue = "1111"),
            @ApiImplicitParam(name = "paramB", value = "参数b", defaultValue = "222"),
    })
    @ApiResCustom(DemoExtendResult.class)
    public void test5(String paramA, String paramB) {
        CordonAlarmData cordonAlarmData = new CordonAlarmData();
        cordonAlarmData.setAction(1);
        cordonAlarmData.setDevId(1);
        cordonAlarmData.setEid(5);
        cordonAlarmData.seteType(24);
        cordonAlarmData.setUpTime(System.currentTimeMillis() / 1000);

        CordonAlarmResult cordonAlarmResult = new CordonAlarmResult();
        cordonAlarmResult.setCode(0);
        cordonAlarmResult.setSysTime(System.currentTimeMillis() / 1000);
        cordonAlarmResult.setData(cordonAlarmData);

        DemoExtendResult demo = new DemoExtendResult();
        demo.setCode(0);
        demo.setMsg("成功");
        demo.setData(cordonAlarmResult);

        this.renderJson(demo);
    }

    @ApiOperation(value = "2.10.1第三方返回值[内部类]", notes = "读取内部类的描述", position = 6)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "paramA", value = "参数a", defaultValue = "1111"),
            @ApiImplicitParam(name = "paramB", value = "参数b", defaultValue = "222"),
    })
    @ApiResCustom(DemoInnerResult.class)
    public void test6(String paramA, String paramB) {

        this.renderJson();
    }

    @ApiOperation(value = "2.10.1第三方返回值[泛型]", notes = "解析泛型<?>", position = 6)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "paramA", value = "参数a", defaultValue = "1111"),
            @ApiImplicitParam(name = "paramB", value = "参数b", defaultValue = "222"),
    })
    @ApiResCustom(GwcGridData.class)
    public void test7(String paramA, String paramB) {

        this.renderJson();
    }

    @ApiOperation(value = "2.10.1第三方返回值[泛型2]", notes = "解析泛型 String", position = 6)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "paramA", value = "参数a", defaultValue = "1111"),
            @ApiImplicitParam(name = "paramB", value = "参数b", defaultValue = "222"),
    })
    @ApiResCustom(GwcGridData2.class)
    public void test8(String paramA, String paramB) {

        this.renderJson();
    }


    @ApiOperation(value = "2.10.1第三方返回值[泛型3]", notes = "解析泛型 EquipDto", position = 6)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "paramA", value = "参数a", defaultValue = "1111"),
            @ApiImplicitParam(name = "paramB", value = "参数b", defaultValue = "222"),
    })
    @ApiResCustom(GwcGridData3.class)
    public void test9(String paramA, String paramB) {

        this.renderJson();
    }
}
